package online.szlib.com.core.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import online.szlib.com.core.domain.CartItem;
import online.szlib.com.core.repositories.CartItemRepository;

@Service("cartService")
public class CartServiceImpl implements CartService {

	@Autowired
	private CartItemRepository cartRepository;
	
	public List<CartItem> listCartItems(){
		return cartRepository.findAll();
	}
	
	public CartItem getCartItem(Long cartItemId){
		return cartRepository.findOne(cartItemId);
	}
	
	public Long create(CartItem cartItem){
		cartRepository.save(cartItem);
		return cartItem.getCartitemId();
	}
	
	public void update(CartItem cartItem){
		cartRepository.saveAndFlush(cartItem);
	}
	
	public void deleteById(Long id){
		cartRepository.delete(id);
	}
}
